/***************************************************************************************
* Copyright (c) 2025-2025 Aiqiang Zhang
*
* NEMU is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

#include <sdb.h>

#define N 65536
void init_regex();
void init_log(const char *log_file);
int main(int argc, char *argv[]) {
    FILE *fp;
    if((fp=fopen(argv[1], "r"))==NULL) {
        perror("Open file failed");
        exit(1);
    }
    char buf[N+64];
    char* token;
    uint32_t res_refer;
    uint32_t res;
    bool success;
    unsigned int lineno = 0;
    init_log(NULL);
    init_regex();
    while((fgets(buf, N, fp))!=NULL) {
        // 测试每一行
        sscanf(buf, "%d", &res_refer);
        token = strtok(buf, " ");
        token = strtok(NULL, "\n");
        res = expr(token, &success);
        if (!success) printf("#%d Failed calculate\n", lineno);
        else {
            if (res!=res_refer) printf("#%d Mismatch %u != %u\n", lineno, res, res_refer);
        }
        lineno += 1;
    }
    return 0;
}

